#ifndef PLAYER_H_
#define PLAYER_H_

#include <stdio.h>
#include <nds.h>
#include "fileinfo.h"
#include "playlist.h"
#include "decoder.h"

#include "command.h"

#define PLAYER_BUFFER_MAX 920
#define PLAYER_BUFFER_DIV 50

enum PlayerStatus
{
	PLAYER_INITIAL,
	PLAYER_PLAY,
	PLAYER_PAUSE,
	PLAYER_STOP
};

enum PlayerMode
{
	PLAYER_NORMAL,
	PLAYER_SHUFFLE,
	PLAYER_REPEAT,
	PLAYER_SHUFFLE_REPEAT
};

class Player {
	
public:
	Player();
	void prev();
	void play();
	void togglepause();
	void toggleplay();
	void stop();
	void next();
	void setMode(PlayerMode newmode);
	bool process();
	void volUp();
	void volDown();
	PlayerStatus getStatus();
	fileTime getTime();
	Playlist playlist;
	
private:
	int16_t buffer_L1[PLAYER_BUFFER_MAX], buffer_R1[PLAYER_BUFFER_MAX],
	        buffer_L2[PLAYER_BUFFER_MAX], buffer_R2[PLAYER_BUFFER_MAX];
	
	bool flag;
	bool buffer_flag;
	uint32_t buffer_size;
	
	fileTime progress;
	fileInfo info;
	Decoder* decoder;
	
	time_t startTime;
	bool scrobbled;
	bool isWiFiCheck;
	bool isWiFi;
	
	uint8_t vol;
	PlayerStatus status;
	uint8_t curPlaying;
	PlayerMode mode;
	uint8_t chanL;
	uint8_t chanR;
	
	void load();
	void playSample();
	void fillBuffer();
	void clearBuffer();
	
	void timerstart();
	void timerstop();
	void timerreset();

	void ARM7setChannel(int channel, int frequency, int length, u8 pan);
	void ARM7updateChannel(int channel, const void* data, int volume);
	void ARM7stopChannel(int channel);
};

#endif /*PLAYER_H_*/
